var $ = require('jquery');
var dayList = require('lib/components/DateRangePicker.jsx').dayList;

require('jquery.cookie');

function getValue () {
  var spanInCookie = $.cookie('spanTime', Number);

  if (spanInCookie) {
    var value = {
      spanTime: spanInCookie,
      endTime: $.cookie('endTime', Number) || null
    };

    return value;
  } else {
    return {
      spanTime: dayList[0].value,
      endTime: null
    };
  }
}

if (BlueWare.userStatus === 'FREE' || BlueWare.userStatus === 'PAIED') {
  var time = getValue();

  if (time.spanTime > 7 * 24 * 60 * 60 * 1000) {
    var option = {
      path: '/'
    };

    if (document.domain.indexOf(BlueWare.siteDomain) > -1) {
      option.domain = BlueWare.siteDomain;
    }

    $.cookie('spanTime', 30 * 60 * 1000, option);
    $.cookie('endTime', null, option);
  }
}



module.exports.getValue = getValue;
